package com.sgb.member.weight;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.sgb.member.R;
import com.sgb.member.databinding.LayoutUploadFileItemBinding;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class UploadFileAdapter extends BaseRecycleAdapter<UploadFileBean> {

    private SimpleResult<Integer> simpleResult;

    public UploadFileAdapter(Context context, List<UploadFileBean> datas, SimpleResult<Integer> simpleResult) {
        super(context, R.layout.layout_upload_file_item, datas);
        this.simpleResult = simpleResult;
    }

    @Override
    public void convert(ItemViewHolder holder, UploadFileBean entity) {
        LayoutUploadFileItemBinding binding = (LayoutUploadFileItemBinding) holder.getmBinding();
        switch (entity.getFileType()) {
            case "image/jpg":
            case "image/png":
            case "image/jpeg":
                Glide.with(context).load(R.mipmap.member_icon_file_img).into(binding.tvFileImg);
                break;
            case "application/msword":
            case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
                Glide.with(context).load(R.mipmap.member_icon_file_doc).into(binding.tvFileImg);
                break;
            case "application/vnd.ms-powerpoint":
            case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
                Glide.with(context).load(R.mipmap.member_icon_file_ppt).into(binding.tvFileImg);
                break;
            case "application/vnd.ms-excel":
            case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
                Glide.with(context).load(R.mipmap.member_icon_file_xlsx).into(binding.tvFileImg);
                break;
            case "application/pdf":
                Glide.with(context).load(R.mipmap.member_icon_file_pdf).into(binding.tvFileImg);
                break;
            default:
                Glide.with(context).load(R.mipmap.member_icon_file_doc).into(binding.tvFileImg);
                break;
        }
        binding.tvFile.setText(entity.getFileName());
        binding.tvFileDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (simpleResult != null) {
                    simpleResult.onResult(holder.getPosition());
                } else {
                    removeItem(holder.getPosition());
                }
            }
        });
    }
}
